package cn.yunhe.service;

import org.hibernate.Session;
import org.hibernate.Transaction;

import cn.yunhe.entity.Essay;
import cn.yunhe.entity.LoginUser;
import cn.yunhe.factory.HibernateSessionFactory;

public class EssayService {
	Session session= null;
	Transaction tr=null;
	
	//添加文章
	public boolean addEssay( String title, String content,String picture, LoginUser loginuser) {
		try {
			Essay essay=new Essay(title,content,picture,loginuser);
			session = HibernateSessionFactory.getSession();
			tr = session.beginTransaction();
			session.save(essay);
			tr.commit();
			return true;	
		} catch (Exception e) {
			e.printStackTrace();
			tr.rollback();
			return false;
		} finally {
			HibernateSessionFactory.closeSession();
		}
	}
}
